import { Player } from './Player';

export class Room {
    public readonly id: string;
    public players: Player[];

    constructor(id: string) {
        this.id = id;
        this.players = [];
    }

    public async addPlayer(playerId: string): Promise<void> {
        if (!this.hasPlayer(playerId)) {
            const player = new Player(playerId);
            this.players.push(player);
        }
    }

    public hasPlayer(playerId: string): boolean {
        return this.players.some(player => player.connectionId === playerId);
    }

    public async handlePlayerMove(playerId: string, direction: string): Promise<void> {
        const player = this.players.find(p => p.connectionId === playerId);
        if (player) {
            player.move(direction);
        }
    }
} 